<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"
	import="java.text.*,java.util.*,java.io.*,com.telecom.cms.dao.*,java.sql.*,com.telecom.cms.util.*,com.telecom.cms.dto.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>导出文件</title>
</head>
<body>
<%
	response.reset();
	SimpleDateFormat dataFormat = new SimpleDateFormat("yyyyMMddHHmm");
	java.util.Date today = new java.util.Date();
	String dateToday = dataFormat.format(today);
	response.setHeader("Content-Disposition", "attachment; filename=\"" + dateToday + ".csv" + "\"");
	response.setCharacterEncoding("GB2312");
	response.setContentType("text/plain;charset=GB2312");
	
	OutputStream os = response.getOutputStream();
	
	String headData = "";
	List rsAtoms = (List) request.getSession().getAttribute("resultAtoms");
	for (int i = 0; i < rsAtoms.size(); i++) {
		SEG_BIZ_ATOM_DEFDTO dto = (SEG_BIZ_ATOM_DEFDTO)rsAtoms.get(i);
		headData += dto.getBIZ_ATOM_NAME().trim() + ",";
	}
	headData += "\n";
	os.write(headData.toString().getBytes("GBK"));
	
	String sql = (String)request.getSession().getAttribute("idaSql");
	int rowCount = ((Integer)request.getSession().getAttribute("rowCount")).intValue();
	String startTime = CurrentTime.getCurrentTime();
	List idaData = (new IdaDAO()).idaQuery(sql, 1, rowCount, false);
	String endTime = CurrentTime.getCurrentTime();
	for (int i = 0; i < idaData.size(); i++){
		String[] row = (String[])idaData.get(i);
		for (int j = 0; j < rsAtoms.size(); j++){
			os.write((row[j] + ",").getBytes("GBK"));
		}
		os.write('\n');
	}
	IdaLogDAO.logExecute(((Long)request.getSession().getAttribute("AccsLogId")).longValue(), "14", sql, rowCount, startTime, endTime, "download result file");

	os.flush();
	os.close();
	out.clear();
	out = pageContext.pushBody();
%>
</body>
</html>
